package main

import (
	"MusicCli/colorschemes"
	ui "github.com/gizak/termui/v3"
	"github.com/gizak/termui/v3/widgets"
	"log"
)

var (
	colorscheme    = colorschemes.Default
)

func setDefaultTermuiColors() {
	ui.Theme.Default = ui.NewStyle(ui.Color(colorscheme.Fg), ui.Color(colorscheme.Bg))
	ui.Theme.Block.Title = ui.NewStyle(ui.Color(colorscheme.BorderLabel), ui.Color(colorscheme.Bg))
	ui.Theme.Block.Border = ui.NewStyle(ui.Color(colorscheme.BorderLine), ui.Color(colorscheme.Bg))
}


func main() {
	if err := ui.Init(); err != nil {
		log.Fatalf("failed to initialize termui: %v", err)
	}
	defer ui.Close()
	//setDefaultTermuiColors()
	table := widgets.NewList()
	table.Title = "List"
	table.Rows = []string{
		"[0]1",
		"[1]1",
		"[2]1",
		"[3]1",
		"[4]1",
		"[5]1",
		"[6]1",
		"[7]1",
		"[8]1",
		"[9]1",
	}
	table.TextStyle = ui.NewStyle(ui.ColorCyan)
	table.BorderStyle = ui.NewStyle(ui.ColorCyan)
	table.SelectedRowStyle = ui.NewStyle(ui.ColorCyan, ui.ColorWhite, ui.ModifierReverse)
	table.WrapText = true
	//l.SetRect(0, 0, 25, 8)

	list := widgets.NewTable()
	list.Title = "List"
	list.Rows = [][]string{
		[]string{"[0]1"},
		[]string{"[1]1"},
		[]string{"[2]1"},
		[]string{"[3]1"},
		[]string{"[4]1"},
		[]string{"[5]1"},
		[]string{"[6]1"},
		[]string{"[7]1"},
		[]string{"[8]1"},
		[]string{"[9]1"},
	}
	list.TextStyle = ui.NewStyle(ui.ColorCyan)
	list.RowSeparator = false
	list.BorderStyle = ui.NewStyle(ui.ColorCyan)
	list.FillRow = true
	//list.RowStyles[0] = ui.NewStyle(ui.ColorWhite, ui.ColorBlack, ui.ModifierBold)
	list.RowStyles[2] = ui.NewStyle(ui.ColorWhite, ui.ColorCyan, ui.ModifierBold)
	//list.RowStyles[3] = ui.NewStyle(ui.ColorYellow)
	//list.SelectedRowStyle = ui.NewStyle(ui.ColorCyan, ui.ColorWhite, ui.ModifierReverse)
	//list.TextStyle.Modifier = ui.ModifierReverse
	//list.WrapText = true

	title := widgets.NewParagraph()
	title.Text = "<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget"
	title.Title = "Home"
	title.BorderStyle = ui.NewStyle(ui.ColorCyan)
	title.TextStyle = ui.NewStyle(ui.ColorCyan)
	//
	//table := widgets.NewParagraph()
	//table.Text = "<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget"
	//table.Title = "Table"
	//
	//list := widgets.NewParagraph()
	//list.Text = "<> This row has 3 columns\n<- Widgets can be stacked up like left side\n<- Stacked widgets are treated as a single widget"
	//list.Title = "List"


	grid := ui.NewGrid()
	termWidth, termHeight := ui.TerminalDimensions()
	grid.SetRect(0, 0, termWidth, termHeight)

	grid.Set(
		ui.NewRow(1.0/10,
			ui.NewCol(1.0, title),
		),
		ui.NewRow(9.0/10,
			ui.NewCol(2.0/10, table),
			ui.NewCol(8.0/10, list),
		),
	)
	ui.Render(grid)
	uiEvents := ui.PollEvents()
	for {
		select {
		case e := <-uiEvents:
			switch e.ID {
			case "<Resize>":
				payload := e.Payload.(ui.Resize)
				grid.SetRect(0, 0, payload.Width, payload.Height)
				ui.Clear()
				ui.Render(grid)
			case "q", "<C-c>":
				return
			case "s":
				table.ScrollDown()
			case "w":
				table.ScrollUp()
			case "j":
				list.
			case "k":
				//list.ScrollUp()
			}
			ui.Render(grid)
		}

	}
}